﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace QuanLyShopCD.BL
{
    class tinh_dm
    {
         AcessData con;
        TextBox txt1,txt2;
        DataGridView dtg;
        DataTable tb;
        public tinh_dm(TextBox tb1,TextBox tb2, DataGridView dg1)
        {
            con = new AcessData();
            this.txt1 = tb1;
            this.txt2 = tb2;
            this.dtg = dg1;
        }
        public tinh_dm()
        {
            con = new AcessData();
        }
        public void hienthi()
        {
            con.Open();
            tb = con.Execute_ps("PS_DM");
            dtg.DataSource = tb;
            con.Close();
            Refesh();
        }
        void Refesh()
        {
            dtg.DataSource = tb;
            txt1.DataBindings.Clear();
            txt2.DataBindings.Clear();
            txt1.DataBindings.Add("Text", tb, "MaDM");
            txt2.DataBindings.Add("Text", tb, "TenDM");
        }
        public void them()
        {
            SqlParameter[] pr ={ new SqlParameter("MaDM",txt1.Text),new SqlParameter("TenDM",txt2.Text)};
            con.Open();
            tb= con.Execute_ps("PS_DANHMUC", pr);
            dtg.DataSource = tb;
            con.Close();
            Refesh();
        }
        public void sua()
        {
            SqlParameter[] pr = { new SqlParameter("MaDM", txt1.Text), new SqlParameter("TenDM", txt2.Text) };
            con.Open();
            tb=con.Execute_ps("PS_SUADM", pr);
            dtg.DataSource = tb;
            con.Close();
            Refesh();
        }
        public void xoa()
        {
            SqlParameter[] pr = { new SqlParameter("MaDM", txt1.Text)};
            con.Open();
            tb =con.Execute_ps("PS_XOADM", pr);
            dtg.DataSource = tb;
            con.Close();
            Refesh();
        }
        public DataTable getDM()
        {
            con.Open();
            return con.Execute_ps("PS_DM");
        }
    }
}

